import 'package:flutter/material.dart';
import 'package:flutter_widget/src/config/color_define.dart';
import 'package:flutter_widget/src/widget/avatar/avatar_widget.dart';

/* 一排头像，可设置重叠 */
class AvatarRowWidget extends StatelessWidget {
  final List<String>? avatars;
  final double avatarWidth;
  final double offset; //设置重叠偏移
  final double avatarBorderWidth; //头像边框大小
  final Color? borderColor; //边框颜色

  const AvatarRowWidget({
    Key? key,
    this.avatars,
    this.avatarWidth = 26,
    this.offset = 6,
    this.avatarBorderWidth = 1,
    this.borderColor,
  }) : super(key: key);

  List<Widget> memberList(BuildContext context, List itemList) => List.generate(
        itemList.length,
        (index) {
          String avatarItem = itemList[itemList.length - 1 - index];
          return Positioned(
            right: index * (avatarWidth - offset),
            top: 0,
            width: avatarWidth,
            height: avatarWidth,
            child: AvatarWidget(
              avatar: avatarItem,
              borderWidth: avatarBorderWidth,
              borderColor: borderColor ?? FWColorPicker.white,
              width: avatarWidth,
              height: avatarWidth,
            ),
          );
        },
      );

  @override
  Widget build(BuildContext context) {
    return SizedBox(
      height: avatarWidth + avatarBorderWidth * 2,
      width: (avatarWidth - offset) * avatars!.length + offset,
      child: Stack(
        children: avatars != null ? memberList(context, avatars!) : [],
      ),
    );
  }
}
